package ScalaStudy.chapter06

object Test07_Inherit {
  def main(args: Array[String]): Unit = {


    /////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////    继承   ///////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////


    //调用
    val student1 = new Student7("1",1)
    println("========================================")
    val student2 = new Student7("1",1,"001")


  }
}


//定义一个父类

class Person7(){
  var name:String = _
  var age: Int = _

  println("1. 父类的主构造器")

  def this(name:String, age:Int){
    this()
    println("2. 父类的辅助构造器调用")
    this.name = name                            //表示辅助构造器调用更改主构造器的属性
    this.age = age
  }
  def Person7(): Unit = {
    println(s"name: ${name}, age: ${age}")
  }
}

//定义子类

//class Student7(name: String, age: Int) extends Person7(name,age){  //调用父类的辅助构造器
class Student7(name: String, age: Int) extends Person7{          //由于Person7有属性，所以子类也可以给父类调用参数
  var stdNo:String = _
  println("3. 子类的主构造器被调用")

  def this(name: String, age:Int, stdNo: String){
    this(name,age)
    println("4. 子类的辅助构造器调用")
    this.stdNo = stdNo

  }
  override def Person7(): Unit = {
    println(s"name: ${name}, age: ${age}, stdNo: ${stdNo}")
  }
}